import { IPSDataEntity } from '../dataentity/ipsdata-entity';
import { IPSDEField } from '../dataentity/defield/ipsdefield';
import { IPSDEDataSet } from '../dataentity/ds/ipsdedata-set';
import { IPSSysSFPlugin } from '../res/ipssys-sfplugin';
import { IPSSystemModule } from '../system/ipssystem-module';
import { IPSWFDEDataSetRole } from './ipswfdedata-set-role';
import { IPSWFRole } from './ipswfrole';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSWFRoleImpl extends PSModelObjectImpl implements IPSWFRole, IPSWFDEDataSetRole {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected psdedataset: IPSDEDataSet | null = null;

  getPSDEDataSet(): IPSDEDataSet | null {
    if (this.psdedataset != null) return this.psdedataset;
    const value = this.M.getPSDEDataSet;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getPSDataEntity();
    if (ipsdataentity != null) {
      this.psdedataset = ipsdataentity.findPSDEDataSet(value);
    }
    return this.psdedataset;
  }

  get psDEDataSet(): IPSDEDataSet | null {
    return this.getPSDEDataSet();
  }

  getPSDEDataSetMust(): IPSDEDataSet {
    const value = this.getPSDEDataSet();
    if (value == null) {
      throw new Error('未指定数据源数据集合');
    }
    return value;
  }

  protected psdataentity: IPSDataEntity | null = null;

  getPSDataEntity(): IPSDataEntity | null {
    if (this.psdataentity != null) return this.psdataentity;
    const value = this.M.getPSDataEntity;
    if (value == null) {
      return null;
    }
    this.psdataentity = this.getPSModel4('dataentity.IPSDataEntity', value, 'getPSDataEntity') as IPSDataEntity;
    return this.psdataentity;
  }

  get psDataEntity(): IPSDataEntity | null {
    return this.getPSDataEntity();
  }

  getPSDataEntityMust(): IPSDataEntity {
    const value = this.getPSDataEntity();
    if (value == null) {
      throw new Error('未指定数据源实体对象');
    }
    return value;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后台扩展插件');
    }
    return value;
  }

  protected pssystemmodule: IPSSystemModule | null = null;

  getPSSystemModule(): IPSSystemModule | null {
    if (this.pssystemmodule != null) return this.pssystemmodule;
    const value = this.M.getPSSystemModule;
    if (value == null) {
      return null;
    }
    this.pssystemmodule = this.getPSModel4('system.IPSSystemModule', value, 'getPSSystemModule') as IPSSystemModule;
    return this.pssystemmodule;
  }

  get psSystemModule(): IPSSystemModule | null {
    return this.getPSSystemModule();
  }

  getPSSystemModuleMust(): IPSSystemModule {
    const value = this.getPSSystemModule();
    if (value == null) {
      throw new Error('未指定系统模块');
    }
    return value;
  }

  get uniqueTag(): string {
    return this.M.uniqueTag;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userData(): string {
    return this.M.userData;
  }

  get userData2(): string {
    return this.M.userData2;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get wFRoleSN(): string {
    return this.M.wFRoleSN;
  }

  get wFRoleType():
    | 'USERGROUP'
    | 'SYSUSERROLE'
    | 'CUSTOM'
    | 'DEDATASET'
    | 'ORG'
    | 'PORG'
    | 'ORGSECTOR'
    | 'PORGSECTOR'
    | 'ORGGROUP'
    | 'ORGSECTORGROUP'
    | 'ORGUSERGROUP'
    | 'ORGSECTORUSERGROUP'
    | 'ORGADMIN'
    | 'ORGSECTORADMIN' {
    return this.M.wFRoleType;
  }

  protected wfuseridpsdef: IPSDEField | null = null;

  getWFUserIdPSDEF(): IPSDEField | null {
    if (this.wfuseridpsdef != null) return this.wfuseridpsdef;
    const value = this.M.getWFUserIdPSDEF;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getPSDataEntity();
    if (ipsdataentity != null) {
      this.wfuseridpsdef = ipsdataentity.findPSDEField(value);
    }
    return this.wfuseridpsdef;
  }

  get wFUserIdPSDEF(): IPSDEField | null {
    return this.getWFUserIdPSDEF();
  }

  getWFUserIdPSDEFMust(): IPSDEField {
    const value = this.getWFUserIdPSDEF();
    if (value == null) {
      throw new Error('未指定流程用户标识存储属性');
    }
    return value;
  }

  protected wfusernamepsdef: IPSDEField | null = null;

  getWFUserNamePSDEF(): IPSDEField | null {
    if (this.wfusernamepsdef != null) return this.wfusernamepsdef;
    const value = this.M.getWFUserNamePSDEF;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getPSDataEntity();
    if (ipsdataentity != null) {
      this.wfusernamepsdef = ipsdataentity.findPSDEField(value);
    }
    return this.wfusernamepsdef;
  }

  get wFUserNamePSDEF(): IPSDEField | null {
    return this.getWFUserNamePSDEF();
  }

  getWFUserNamePSDEFMust(): IPSDEField {
    const value = this.getWFUserNamePSDEF();
    if (value == null) {
      throw new Error('未指定流程用户名称存储属性');
    }
    return value;
  }

  get cls(): string {
    return 'PSWFRoleImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'wf.IPSWFDEDataSetRole' || cls == 'wf.IPSWFRole') return true;
    return super.instanceof(cls);
  }
}
